/*******************************************************
> Copyright (C) 2024 ==IOT== All rights reserved.
> File Name: 2-接收-receive.c
> Author: wyf
> Website:www.lv1.org
> Created Time: 2024年08月06日 星期二 11时30分22秒
***************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h>
#include <assert.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <time.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <sys/shm.h>
typedef struct student
{
	int id;
	char name[20];
	struct student *next;
}STU;

int main(int argc, const char* argv[])
{
		key_t key = 0;
	int shmid = 0;
	int ret = 0;

	key = ftok("./",1);
	if(key == -1)
	{
		perror("ftok");
		exit(-1);
	}

	shmid = shmget(key,1024,IPC_CREAT|0600);
	if(shmid == -1)
	{
		perror("shmget");
		exit(-1);
	}


	STU *str = NULL;

	str = shmat(shmid,NULL,0);
	if(str == (void *)-1)
	{
		perror("shmat");
		exit(-1);
	}
	
	STU k;
	memcpy(&k,str,sizeof(STU));
	printf("结果：%d %s\n",k.id,k.name);

	ret = shmdt(str);
	if(ret == -1)
	{
		perror("shmdt");
		exit(-1);
	}
    return 0;
}
